package com.wuhan.template.module.home.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseFragment;
import com.wuhan.template.constant.Urls;
import com.wuhan.template.module.home.adapter.BaoLiaoAdapter;
import com.wuhan.template.module.home.entity.BaoLiaoEntity;
import com.wuhan.template.utils.EventMessage;
import com.wuhan.template.utils.OkHttpUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/11 0011.
 */
public class DaJiaBaoLiaoFragment extends BaseFragment {

    @BindView(R.id.baoliao_pullView)
    protected PullToRefreshListView listView ;
    public DaJiaBaoLiaoFragment() {
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_dajia_baoliao;
    }

    public static DaJiaBaoLiaoFragment newInstance(String type) {

        Bundle args = new Bundle();

        DaJiaBaoLiaoFragment fragment = new DaJiaBaoLiaoFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    protected void initViews() {
        super.initViews();
    }

    @Override
    protected void loadData() {
        OkHttpUtils.get(Urls.BaoLiao, null);

    }

    @Override
    protected void postEventResult(@NonNull EventMessage message) {
        if (message.type.equals(Urls.BaoLiao)) {
            Gson gson = new Gson();
            BaoLiaoEntity[] baoLiaos = gson.fromJson(message.result, BaoLiaoEntity[].class);
            List<BaoLiaoEntity> list = new ArrayList();
            list.addAll(java.util.Arrays.asList(baoLiaos));
            BaoLiaoAdapter baoLiaoAdapter = new BaoLiaoAdapter(getContext(),list);
            listView.setAdapter(baoLiaoAdapter);
            baoLiaoAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

        super.onViewCreated(view, savedInstanceState);
        //ButterKnife.bind(this, view);
    }
}
